/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jmediaplayer;

import java.io.*;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

class FileTree
{
	public static void main(String[] args)
	{
		//LoopFolders(new File("."), tree);
	}

	public static void getFolders(String Folder, JTree tree)
	{
		DefaultMutableTreeNode node = new javax.swing.tree.DefaultMutableTreeNode("Media");
		DefaultMutableTreeNode endNode = LoopFolders(new File(Folder), tree, node);
		tree.setModel(new javax.swing.tree.DefaultTreeModel(endNode));
	}


	public static DefaultMutableTreeNode LoopFolders(File path, JTree tree, DefaultMutableTreeNode node)
	{
		File [] files = path.listFiles();

		for (int i = 0; i < files.length; i++) {
			//System.out.println(files[i]);
			//Tutorial Continued
			//DefaultMutableTreeNode node3 = new DefaultMutableTreeNode(files[i]);
			//node.add(node3);

			//We do not want to ever read hidden files in this process.
			if (!files[i].getName().startsWith(".") || !files[i].isHidden()) {
				if (files[i].isDirectory()) {
					//group them within here
					DefaultMutableTreeNode node2 = new javax.swing.tree.DefaultMutableTreeNode(files[i].getName());

					DefaultMutableTreeNode node3 = LoopFolders(files[i], tree, node2);
					node.add(node3);
				} else {
					//DefaultMutableTreeNode node2 = new javax.swing.tree.DefaultMutableTreeNode(files[i]);
					//node.add(node2);
				}
			}
		}

		return node;
	}
}
